//
//  FirstViewController.m
//  Demo0039
//
//  Created by zTercel on 13-4-18.
//  Copyright (c) 2013年 zTercel. All rights reserved.
//

#import "FirstViewController.h"
#import "DetailViewController.h"

@interface FirstViewController ()

@end

@implementation FirstViewController
static NSString  *cellIdentifier = @"cellIdentifier";

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
        self.title     = @"first level View";
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
 
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellIdentifier];
    self.items   = @[@"Tom", @"zTercel", @"yTercel"];
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.items.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
    cell.textLabel.text     = self.items[indexPath.row];
    cell.accessoryType      = UITableViewCellAccessoryDetailDisclosureButton;
    
    return cell;
}

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString    *prompt     = [NSString stringWithFormat:@"You select item is \"%@\"", self.items[indexPath.row]];
    UIAlertView *alertView  = [[UIAlertView alloc]initWithTitle:@"Select Item"
                                                        message:prompt
                                                       delegate:self
                                              cancelButtonTitle:@"Yes, it's right"
                                              otherButtonTitles:nil];
    [alertView show];
}

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
    DetailViewController*   detailViewController    = [[DetailViewController alloc]init];
    detailViewController.message    = [NSString stringWithFormat:@"This view is subclass of firstlevelView"];
    detailViewController.title      = [NSString stringWithFormat:@"%@", self.items[indexPath.row]];
    [self.navigationController pushViewController:detailViewController animated:YES];
}
@end
